package com.mock.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.mock.engineerprocess.domain.MockUserStorage;
import com.mock.engineerprocess.domain.impl.MockUserStorageImpl;
import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.RCEmployeeUser;
import edu.fudan.langlab.domain.organization.Party;
import edu.fudan.langlab.domain.security.ISystemUserService;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.mock.engineerprocess.domain.MockSystemUserService")
public class MockSystemUserServiceImpl extends BaseService implements ISystemUserService {
  public User getCurrentUser() {
    User _xblockexpression = null;
    {IGenericQuery<MockUserStorage> query=getObjectFactory().createGenericQuery(MockUserStorage.class,"select e from com.mock.engineerprocess.domain.impl.MockUserStorageImpl as e   where  e.active = 1      ");
      MockUserStorage _uniqueResult = query.uniqueResult();
      final User result = _uniqueResult==null?(User)null:_uniqueResult.getUser();
      User _xifexpression = null;
      boolean _notEquals = (!Objects.equal(result, null));
      if (_notEquals) {
        _xifexpression = result;
      } else {
        _xifexpression = null;
      }
      _xblockexpression = (_xifexpression);
    }
    return _xblockexpression;
  }
  
  public void setCurrentUser(final User user) {IGenericQuery<MockUserStorage> query=getObjectFactory().createGenericQuery(MockUserStorage.class,"select e from com.mock.engineerprocess.domain.impl.MockUserStorageImpl as e   where  e.active = 1      ");
    Collection<MockUserStorage> _list = query.list();
    final Procedure1<MockUserStorage> _function = new Procedure1<MockUserStorage>() {
        public void apply(final MockUserStorage it) {getObjectFactory().delete(it);
          
        }
      };
    IterableExtensions.<MockUserStorage>forEach(_list, _function);MockUserStorageImpl.create(user,getObjectFactory());
  }
  
  public Party getCurrentUserAsParty() {
    User _currentUser = this.getCurrentUser();
    RCEmployee _employee = ((RCEmployeeUser) _currentUser).getEmployee();
    return _employee;
  }
  
  public void logout() {
  }
}
